﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ghy.Soft.Domain.Entities;
using NHibernate;
using NHibernate.Criterion;
using System.Collections;

namespace Ghy.Soft.Data
{
    public class AdminDao : BaseDao<Admin>
    {
        public Admin GetAdminByUsernameAndPassword(String username, String password)
        {
            using (ISession session = FluentFactory.GetSession())
            {
                ICriteria criteria = session.CreateCriteria<Admin>().Add(Expression.Eq("AdminName", username)
                    ).Add(Expression.Eq("Password", password));
                IList<Admin> list = criteria.List<Admin>();
                if (list.Count == 0)
                {
                    return null;
                }
                else
                {
                    return list[0];
                }
            }
        }

        public List<Admin> GetAllAdmins()
        {
            using (ISession session = FluentFactory.GetSession())
            {
                return session.CreateCriteria<Admin>().List<Admin>() as List<Admin>;
            }
        }
    }
}
